package com.ruoyi.whc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.whc.domain.Positive;
import com.ruoyi.whc.service.IPositiveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 阳性人员记录Controller
 * 
 * @author ruoyi
 * @date 2022-09-22
 */
@RestController
@RequestMapping("/whc/positive")
public class PositiveController extends BaseController
{
    @Autowired
    private IPositiveService positiveService;

    /**
     * 查询阳性人员记录列表
     */
    @PreAuthorize("@ss.hasPermi('whc:positive:list')")
    @GetMapping("/list")
    public TableDataInfo list(Positive positive)
    {
        startPage();
        List<Positive> list = positiveService.selectPositiveList(positive);
        return getDataTable(list);
    }

    /**
     * 导出阳性人员记录列表
     */
    @PreAuthorize("@ss.hasPermi('whc:positive:export')")
    @Log(title = "阳性人员记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Positive positive)
    {
        List<Positive> list = positiveService.selectPositiveList(positive);
        ExcelUtil<Positive> util = new ExcelUtil<Positive>(Positive.class);
        util.exportExcel(response, list, "阳性人员记录数据");
    }

    /**
     * 获取阳性人员记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('whc:positive:query')")
    @GetMapping(value = "/{pid}")
    public AjaxResult getInfo(@PathVariable("pid") Long pid)
    {
        return AjaxResult.success(positiveService.selectPositiveByPid(pid));
    }

    /**
     * 新增阳性人员记录
     */
    @PreAuthorize("@ss.hasPermi('whc:positive:add')")
    @Log(title = "阳性人员记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Positive positive)
    {
        return toAjax(positiveService.insertPositive(positive));
    }

    /**
     * 修改阳性人员记录
     */
    @PreAuthorize("@ss.hasPermi('whc:positive:edit')")
    @Log(title = "阳性人员记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Positive positive)
    {
        return toAjax(positiveService.updatePositive(positive));
    }

    /**
     * 删除阳性人员记录
     */
    @PreAuthorize("@ss.hasPermi('whc:positive:remove')")
    @Log(title = "阳性人员记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pids}")
    public AjaxResult remove(@PathVariable Long[] pids)
    {
        return toAjax(positiveService.deletePositiveByPids(pids));
    }
}
